package com.topwater.topwater.controller;

import com.topwater.topwater.entity.SyCosttype;
import com.topwater.topwater.service.SyCosttypeService;
import org.springframework.web.bind.annotation.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.*;

import javax.annotation.Resource;

import com.topwater.topwater.utils.ResponseData;

import java.io.IOException;

import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

import java.util.List;

/**
 * (SyCosttype)表控制层
 *
 * @author 胡文
 * @since 2023-08-23 16:37:19 生成
 */
@RestController
@RequestMapping("syCosttype")
@Api(tags = "SyCosttype模块接口说明")
public class SyCosttypeController {
    /**
     * 服务对象
     */
    @Autowired
    private SyCosttypeService syCosttypeService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @Operation(summary = "通过id查询SyCosttype数据的方法")
    @GetMapping(value = "{id}", produces = {"application/json;charset=UTF-8"})
    public ResponseData queryById(@PathVariable("id") Integer id) {
        return ResponseData.ok().putDataValue("obj", this.syCosttypeService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param syCosttype 实体
     * @return 新增结果
     */
    @Operation(summary = "添加SyCosttype表")
    @PostMapping(value = "add", produces = {"application/json;charset=UTF-8"})
    public ResponseData add(SyCosttype syCosttype) {
        return ResponseData.ok().putDataValue("obj", this.syCosttypeService.insert(syCosttype));
    }

    /**
     * 新增数据
     *
     * @param syCosttype 实体
     * @return 新增结果
     */
    @Operation(summary = "添加SyCosttype表")
    @PostMapping(value = "addNotNull", produces = {"application/json;charset=UTF-8"})
    public ResponseData addNotNull(SyCosttype syCosttype) {
        return ResponseData.ok().putDataValue("obj", this.syCosttypeService.insertNotNull(syCosttype));
    }

    /**
     * 编辑数据
     *
     * @param syCosttype 实体
     * @return 编辑结果
     */
    @Operation(summary = "修改SyCosttype表,根据id修改")
    @PostMapping(value = "update", produces = {"application/json;charset=UTF-8"})
    public ResponseData update(SyCosttype syCosttype) {
        return ResponseData.ok().putDataValue("obj", this.syCosttypeService.update(syCosttype));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @Operation(summary = "删除SyCosttype,根据id删除")
    @PostMapping(value = "deleteById", produces = {"application/json;charset=UTF-8"})
    public ResponseData deleteById(Integer id) {
        return ResponseData.ok().putDataValue("obj", this.syCosttypeService.deleteById(id));
    }

    //单字符串全部模糊查询 带分页
    @Operation(summary = "模糊查询SyCosttype 分页,一个字符串模糊查所有列")
    @GetMapping(value = "queryByLike2", produces = {"application/json;charset=UTF-8"})
    public ResponseData queryByLike2(String str,
                                     @ApiParam("第几页")
                                     @RequestParam(defaultValue = "1", required = false) int pageNum,
                                     @ApiParam("每页多少条")
                                     @RequestParam(defaultValue = "10", required = false) int pageSize) {

        PageHelper.startPage(pageNum, pageSize);
        List<SyCosttype> list = this.syCosttypeService.queryByLike2(str);
        PageInfo pageInfo = new PageInfo<SyCosttype>(list, 7);
        return ResponseData.ok().putDataValue("pageInfo", pageInfo);
    }

    //带分页的模糊查询
    @Operation(summary = "带分页的模糊查询SyCosttype ,主要用这个即可")
    @GetMapping(value = "queryByLike", produces = {"application/json;charset=UTF-8"})
    public ResponseData queryByLike(SyCosttype syCosttype,
                                    @ApiParam("第几页")
                                    @RequestParam(defaultValue = "1", required = false) int pageNum,
                                    @ApiParam("每页多少条")
                                    @RequestParam(defaultValue = "10", required = false) int pageSize) {

        PageHelper.startPage(pageNum, pageSize);
        List<SyCosttype> list = this.syCosttypeService.queryByLike(syCosttype);
        PageInfo pageInfo = new PageInfo<SyCosttype>(list, 7);
        return ResponseData.ok().putDataValue("pageInfo", pageInfo);
    }

}

